import common
import pymysql


class Student:

    def __init__(self, no, name, sex, birth, addr, college):
        self.no = no
        self.name = name
        self.sex = sex
        self.birth = birth
        self.addr = addr
        self.college = college

    def __str__(self):
        return f'{self.no}: {self.name}'


conn = common.get_conn(database='school')
try:
    with conn.cursor(pymysql.cursors.DictCursor) as cursor:
        cursor.execute('select stuid as no, stuname as name, '
                       'stusex as sex, stubirth as birth, '
                       'stuaddr as addr, collid as college '
                       'from tb_student')
        for row in cursor.fetchall():
            student = Student(**row)
            print(student)
except pymysql.MySQLError as err:
    print(err)
finally:
    conn.close()
